package num704;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 21:56
 * @Desc :
 */
public class Solution {
  public int search(int[] nums, int target) {
    int left = 0;
    int right = nums.length - 1;
    while (left <= right) {
      int index = left + (right - left) / 2;
      if (nums[index] == target)
        return index;
      else if (nums[index] > target)
        right = index - 1;
      else
        left = index + 1;
    }
    return -1;
  }
}
